﻿using System.Xml.Linq;
using AzukiMap.MapSource;

namespace AzukiMap.Layer
{
    public class BingLayer : MercatorQuadLayer
    {
        private readonly BingSource _veSource;

        public BingLayer()
        {
        }

        public BingLayer(BingSource tileData, string name)
            : base(tileData, name)
        {
            _veSource = tileData;
        }

        protected override string CreateTileReqString(double tileScale, int pixX, int pixY)
        {
            int level = GetScaleLevel(tileScale);
            int tileX = pixX / _veSource.TileWidth;
            int tileY = pixY / _veSource.TileHeight;
            string tileId = VirtualEarthTileSystem.TileXYToQuadKey(tileX, tileY, level);

            BingLayerType lType = _veSource.TileType;
            string prefix = _veSource.TilePrefixes[lType];
            string extension = _veSource.TileExtensions[lType];
            string additions = _veSource.AdditionalParams[lType];

            return prefix + tileId + extension + additions;
        }

        public override XElement ToXml()
        {
            return ToXml("BingLayer");
        }

        /*
        protected override IPoint GetGeoPointFromTileCoord(int tx, int ty, double tileScale)
        {
            double lon = 0;
            double lat = 0;
            int level = GetScaleLevel(tileScale); 
            VirtualEarthTileSystem.PixelXYToLatLong(tx, ty, level, out lat, out lon);

            return new Geometries.Point(lon, lat) {SRID = 4326};
        }
         */

        /*
        protected override ICoordinate GetGeoPointFromTileCoord(int tx, int ty, double tileScale)
        {
            double lon = 0;
            double lat = 0;
            int level = GetScaleLevel(tileScale); 
            VirtualEarthTileSystem.PixelXYToLatLong(tx, ty, level, out lat, out lon);

            return new Geometries.Coordinate(lon, lat);
        }
         */
    }
}